'use strict';
	angular.module('inventory.storageItemQueryList', ['app.services'])

	.controller('storageItemQueryListCtrl' ,['$rootScope', '$scope', 'BizData' , f])
    function f($rootScope, $scope, BizData) {

		var Model = this;
		
		var options = {};
		options.container = Model;
		options.concept = 'StorageItem';
		options.name = 'dataMaster';
		options.url = $rootScope.path;
		options.httpUrl = $rootScope.getServiceName();
		options.reader = '/inventory/storageItemQuery/list/query';
		options.writer = '';
		options.deleter = '';
		options.idColumnDefine = "fID";
		options.idColumnName = "fID";
		options.isTree = false;
		options.parentRelation = 'fParent';
		options.nodeKindRelation = 'nodeKind';
		options.nodeLevelRelation = 'nodeLevel';
		options.pathRelation = 'fID';
		options.directDeleteMode = true;
		options.limit = 12;
		options.orderBy = "FileItem.itemNo ASC";
		//聚合列
		//options.aggregateColumns = {"StorageItem.itemQuantityL":{name:"sumQuantityL",type:"Decimal",label:""},"CONVERT(FileItem.costingAmountPer*StorageItem.itemQuantityL,decimal(38,2))":{name:"sumCostingAmount",type:"Decimal",label:""},"StorageItem.pieceQuantityL":{name:"sumPieceQuantityL",type:"Decimal",label:""}};
		options.aggregateColumns = {"StorageItem.itemQuantityL":{name:"sumQuantityL",type:"Decimal",label:""},"StorageItem.costingAmount":{name:"sumCostingAmount",type:"Decimal",label:""},"StorageItem.pieceQuantityL":{name:"sumPieceQuantityL",type:"Decimal",label:""}};
		
		Model.dataMaster = new BizData(options);
		//Model.dataMaster.setFilter('nodeKind',"FileItem.nodeKind='nkLeaf'");

		//监视对象中的所有变动
//		Model.dataMaster.deregRows = $scope.$watch('Model.dataMaster.rows',Model.dataMaster.watchRows,true);//true代表深度监视，包括对象的属性，而不是简单的一个值
		//////////////////////////////////////////////
		
		//刷新数据
		Model.refresh = function(){
			Model.dataMaster.refreshData();
		}
		
		
	    //只显示库存大于0的项目
	    $scope.checkboxModel = {
	    	       value1 : false,
	    	       value2 : false,
	    	       value3 : true
	    	     };
	    
	    Model.checkbox1Click = function(){
	    	if($scope.checkboxModel.value1==true){
	    		//添加过滤条件，还为搞定。。。。。。
	    		Model.dataMaster.setFilter('checkbox1','StorageItem.itemQuantityL>0');
//	    		console.log('true');
	    	}else{
	    		Model.dataMaster.deleteFilter('checkbox1');
//	    		console.log('false');
	    	}
			//刷新数据
	    	Model.refresh();
	    };
	    
	    //只显示库存预警项目
	    Model.checkbox2Click = function(){
	    	if($scope.checkboxModel.value2==true){
	    		//添加过滤条件，还为搞定。。。。。。
	    		Model.dataMaster.setFilter('checkbox2','(StorageItem.itemQuantityL-StorageItem.minQuantity)<0');
//	    		console.log('true');
	    	}else{
	    		Model.dataMaster.deleteFilter('checkbox2');
//	    		console.log('false');
	    	}
			//刷新数据
	    	Model.refresh();
	    };
	    /*
	    Model.checkbox3Click = function(){
	    	if($scope.checkboxModel.value3==true){
	    		//添加过滤条件，还为搞定。。。。。。
	    		Model.dataMaster.deleteFilter('fParent');
	    		Model.dataMaster.setFilter('nodeKind',"FileItem.nodeKind='nkLeaf'");
//	    		console.log('true');
	    	}else{
	    		Model.dataMaster.deleteFilter('nodeKind');
	    		Model.dataMaster.setFilter('fParent','FileItem.fParent is null');
//	    		console.log('false');
	    	}
			//刷新数据
		    Model.dataMaster.refreshData();
	    };
	    */
		////////////////////启动执行结束///////////////////////////////////////////////////
		
		Model.refresh();
		
	    return Model;
		
	}	
	
